import random

from wcs.libs.items import items
from wcs.libs.players import players

itemName = "Potion of Healing"
item = items.addItem(itemName)
item.setGroup("special")
item.setCost(800)
item.setDescription("Regain some lost health.")
item.aliveToUse = True
item.setMaxCount(3)

def wcs_item_bought(event_var):
    """
    Executed when a player has purchased an item. If the item purcahsed was this
    item, then add a random number of health between 13 and 27.
    """
    if event_var['item'] == "Potion of Healing":
        userid = event_var["userid"]
        player = players[userid]
        player.heal(random.randint(13, 27))
